package com.db.transaction.manager.entity;

import java.lang.reflect.Constructor;
import java.lang.reflect.Method;

/**
 * @Auther:
 * @Description:
 * @Date: 2019/10/22 17:30
 */
public class Test {
    public static void main(String[] args) throws Exception {
//        Agent agent = new Agent();
//        agent.setId("123");
//        Class<?> agentClass = agent.getClass();
//        Class<Agent> agentClass = Agent.class;
//        Method getId = agentClass.getDeclaredMethod("getId", null);
//        String invoke = (String) getId.invoke(agent);
//        System.out.println(invoke);

        main1(Agent.class, "getId");


    }

    public static void main1(Class clz, String methodName) throws Exception {
        Constructor constructor = clz.getConstructor();
        Object o = constructor.newInstance();
        Class<?> aClass = o.getClass();
        Method declaredMethod = aClass.getDeclaredMethod(methodName, null);
        Method setId = aClass.getDeclaredMethod("setId", String.class);
        Object invoke1 = setId.invoke(o, "333");
        Object invoke = declaredMethod.invoke(o);
        System.out.println(invoke);
    }
}
